import { onMounted, reactive, ref } from "vue";
import { useStore } from "./store";

export default function useSearch(path: string): any {
  const store = useStore();
  const data = ref([]);

  const dataFetch = async () => {
    data.value = await store.dispatch(path, { q: query.q });
  };

  const query = reactive({
    q: "",
    start: 1,
    limit: 10,
  });

  onMounted(dataFetch);

  return {
    data,
    dataFetch,
    query,
  };
}
